package com.liujit.standard.basis.core.enums;

/**
 * @description: 返回结果状态码
 * @author: liujun
 * @create: 2020/12/31 4:27 下午
 **/
public enum ResultCode {

    SUCCESS(1, "成功"),
    FAILURE(0, "失败"),
    USER_NOT_EXIST(0, "账号不存在"),
    USER_ACCOUNT_FORBIDDEN(0, "该用户已禁用，请联系管理员"),
    USER_LOGIN_ERROR(0, "密码错误"),
    USER_HAS_EXISTED(0, "用户已存在"),
    PERMISSION_NO_ACCESS(0, "无访问权限"),
    USER_NOT_LOGGED_IN(-1, "用户未登录"),
    SYSTEM_INNER_ERROR(0, "内部错误，请稍后重试");

    private Integer code;

    private String msg;

    ResultCode(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Integer code() {
        return this.code;
    }

    public String msg() {
        return this.msg;
    }

    public static String getMessage(String name) {
        for (ResultCode item : ResultCode.values()) {
            if (item.name().equals(name)) {
                return item.msg;
            }
        }
        return name;
    }

    public static Integer getCode(String name) {
        for (ResultCode item : ResultCode.values()) {
            if (item.name().equals(name)) {
                return item.code;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.name();
    }
}
